package com.liangjie;

public class IndexOfDemo {
	public static void main(String[] args) {
		String str = "abcbdcabacaabc";
		System.out.println(count(str));
	}

	public static int count(String str) {
		int index = 0;
		int counter = 0;
		
		while (index < str.length()) {
			if (str.indexOf("ab", index) >= 0) {
				index = str.indexOf("ab", index) + 1;
				counter ++;
			} else {
				return counter;
			}
			
		}

		return counter;
	}
}
